<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.metagurukul.metagranth.vo.Tag"%>
<%@page import="com.metagurukul.metagranth.vo.Question"%>
<%@include file="header.jsp"%>
<%
	Question editingQuestion = (Question)request.getAttribute("questionToBeUpdated"); 
	ArrayList<Tag> tags = (ArrayList<Tag>)request.getAttribute("tagsToBeUpdated");
	Iterator itr = tags.iterator();
	String tagName= null;
	
	StringBuilder tagStringBuilder = new StringBuilder() ;
	Tag tag = new Tag(); 
	
	 while(itr.hasNext()){
		tag = (Tag)itr.next();
		tagName = tag.getTagName();		
		tagStringBuilder.append(tagName+", ");
	 }
	 int lastComma = tagStringBuilder.lastIndexOf(",");
	 
	 String tagList = tagStringBuilder.substring(0,lastComma);
	
	%>
<div class="wrappermiddle" align="left">
	<form action="editingQuestion.do" method="POST" name="post-from" onsubmit="return postQuestionForm()">
		<section id="main">
		<div class="module_content">
			<article class="module width_full"> <header>
			<h3>Edit Your Question</h3>
			</header>
			<div class="module_content">
				<fieldset><input type="hidden" name="questionID" value="<%= editingQuestion.getQuesId()%>" />
					<label>Question Title</label> <input type="text" style="width: 96%;" id="titlename" name="titlename" value="<%= editingQuestion.getTitle() %>">
					<br><span id="errorspan1" style="padding-left:12px;padding-top:12px; color: Red;font-family: Arial, Helvetica, sans-serif;font-size: 11px;"></span>
				</fieldset>
				<fieldset>
					<label>Question Description </label>
					<textarea rows="12" name="description" id="description"><%= editingQuestion.getQuestion() %></textarea>
					<br><span id="errorspan2" style="padding-left:12px;padding-top:12px; color: Red;font-family: Arial, Helvetica, sans-serif;font-size: 11px;"></span>
				</fieldset>
				<fieldset style="width: 60%; float: left;">
					<!-- to make two field float next to one another, adjust values accordingly -->
					<label>Tags ( Tag Separate by comma ( , ) like java, ios,
						iphone, asp.net )</label> <input type="text" style="width: 92%;"
						placeholder="At least one tag such as (java, ios, iphone, asp.net)"
						id="tagnames" name="tagnames" value="<%= tagList %>">
						<br><span id="errorspan3" style="padding-left:12px;padding-top:12px; color: Red;font-family: Arial, Helvetica, sans-serif;font-size: 11px;"></span>
				</fieldset>
				<div class="clear"></div>
				<div class="submitdiv">
					<input type="submit" value="" class="btn_update">
				</div>
				<div class="clear"></div>
			</div>
			<footer> </footer> </article>
		</div>
		</section>
	</form>
</div>
<%@include file="footer.jsp"%>